package com.qiche.service.impl;

import java.util.List;

import com.qiche.model.Region;
import com.qiche.service.RegionService;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import tk.mybatis.mapper.entity.Example;

/**
 * Created by Linzw on 2018/01/24.
 */
@Service("regionService")
public class RegionServiceImpl extends BaseService<Region> implements RegionService {

	@Override
	public PageInfo<Region> selectByPage(Region merchant, int start, int length) {
		int page = start / length + 1;
		Example example = new Example(Region.class);
		Example.Criteria criteria = example.createCriteria();
		// 分页查询
		PageHelper.startPage(page, length);
		List<Region> regionList = selectByExample(example);
		return new PageInfo<>(regionList);
	}

	@Override
	public Region selectById(Long regionId) {
		Example example = new Example(Region.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("id", regionId);
		List<Region> regionList = selectByExample(example);
		if (regionList.size() > 0) {
			return regionList.get(0);
		}
		return null;
	}

	@Override
	public List<Region> selectAll() {
		return selectByExample(null);
	}

}
